package com.ruoyi.project.test.image;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class GdsToTiffConverter {

    public static void main(String[] args) {
        try {
            // 读取GDS文件
            String gdsPath = "C:\\Users\\admin\\Desktop\\项目相关资料\\数字光刻机\\gds相关资料\\画图测试\\cell8.gds";
            File gdsFile = new File(gdsPath);
            // 读取GDS数据并进行处理
            // ...

            // 创建一个BufferedImage对象
            int width = 2500;  // TIFF图像的宽度
            int height = 2500; // TIFF图像的高度
            BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

            // 获取Graphics2D对象
            Graphics2D g2d = image.createGraphics();

            // 设置绘制颜色和坐标转换
            /*g2d.setColor(Color.RED);
            g2d.translate(50, 50);
            g2d.fill(Shape);*/

            g2d.setColor(Color.WHITE);
            g2d.fillRect(0, 0, width, height);

            AffineTransform transform = new AffineTransform();
            transform.scale(1, -1); // 沿y轴翻转
            transform.translate(0, -height); // 平移坐标系，使原点位于底部
            g2d.setTransform(transform);

            g2d.translate(50,50);


            g2d.setColor(Color.BLACK);
            Polygon polygon = new Polygon();
            polygon.addPoint(24 ,-3);
            polygon.addPoint(20 ,-5);
            polygon.addPoint(16 ,-3);
            polygon.addPoint(15 ,0);
            polygon.addPoint(16 ,3);
            polygon.addPoint(20 ,5);
            polygon.addPoint(24 ,3);
            polygon.addPoint(25 ,0);
            polygon.addPoint(24 ,-3);
            g2d.fillPolygon(polygon);

            Polygon polygon1 = new Polygon();
            polygon1.addPoint(-10 ,-10);
            polygon1.addPoint(10 ,-10);
            polygon1.addPoint(10 ,10);
            polygon1.addPoint(-10 ,10);
            polygon1.addPoint(-10 ,-10);
            g2d.fillPolygon(polygon1);
            Polygon polygon2 = new Polygon();
            polygon2.addPoint(15 ,-20);
            polygon2.addPoint(25 ,-20);
            polygon2.addPoint(25 ,-10);
            polygon2.addPoint(15 ,-10);
            polygon2.addPoint(15 ,-20);
            g2d.fillPolygon(polygon2);
            Polygon polygon3 = new Polygon();
            polygon3.addPoint(-20 ,15);
            polygon3.addPoint(-25 ,20);
            polygon3.addPoint(-35 ,10);
            polygon3.addPoint(-20 ,10);
            polygon3.addPoint(-20 ,15);
            g2d.fillPolygon(polygon3);

//            g2d.drawString("Hello, BufferedImage!", 100, 100);

            // 在BufferedImage上绘制GDS数据
            // ...
            /*for (int i = 0; i < 300; i++) {
                image.setRGB(100+i,100,0xFF7D40);
            }*/

            // 保存绘制结果为新的TIFF文件
            String outputTiffPath = "C:\\Users\\admin\\Desktop\\output.tiff";
            File outputFile = new File(outputTiffPath);
            ImageIO.write(image, "TIFF", outputFile);

            System.out.println("成功将GDS数据转换为TIFF并保存为新的文件：" + outputTiffPath);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
